﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="giamsatnuocthai1.aspx.cs" Inherits="Giamsatdinhky_giamsatnuocthai1" Title="Untitled Page" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   
             
         <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

            <script type="text/javascript">
            function RowDblClick(sender, eventArgs)
            {
              sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
            }
            </script>

        </telerik:RadCodeBlock>
                 <fieldset id="divNhapLieu" style="width:400px;">
<legend><img style="cursor:pointer" id="imgShowHide" onclick="showHideForm();" width="20px" height="20px" src="../images/qsfConfigDownArrow.png" align="left"/><span style="color: #666633; font-family: Verdana"><strong>
Tìm kiếm</strong></span></legend>
<table cellpadding="2" cellspacing="1"  id="tblTimKiem">

<tr style="height: 19px;">
		<td style="width: 146px"><span style="font-size: 9pt; color: #000000;margin-left:10px">
		    Đợt giám sát:</span>
    </td>
        <td style="width: 369px">
            <telerik:RadComboBox ID="RadComboBox_dotgs" runat="server" DataSourceID="giamsat_dotgs" AllowCustomText="true"
            DataTextField="Dotgiamsat" DataValueField="Madotgs" MarkFirstMatch="true" EnableLoadOnDemand="true" HighlightTemplatedItems="true">
            </telerik:RadComboBox>        
    </td>
</tr>
<tr style="height: 19px;">
		<td style="width: 146px"><span style="font-size: 9pt; color: #000000;margin-left:10px;">
		    Doanh nghiệp</span>
    </td>
        <td style="width: 369px">
              <telerik:RadComboBox ID="RadComboBox_dn" runat="server" DataSourceID="giamsat_dn" 
              DataTextField="TenDN" DataValueField="Madnghiep" AllowCustomText="true" MarkFirstMatch="true" EnableLoadOnDemand="true" HighlightTemplatedItems="true">
            </telerik:RadComboBox>       
    </td>
</tr>
		<tr>
            <td  colspan="2" align="center">
                <table width="100%"><tr><td style="height: 25px">
                <telerik:RadButton ID="RadButton1" runat="server" Text="Tìm kiếm" Skin="Hay" OnClick="Button1_Click">
                    </telerik:RadButton> </td>
                </tr></table>
      </td></tr>
    </table>
</fieldset>
         <!-- load ajax-->
         
   <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid_gsat">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid_gsat" LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="divMsgs" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
        </telerik:RadAjaxManager>
        <!-- end-->
        
         <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" 
            BackColor="#99FF66" Skin="WebBlue" />
        <telerik:RadGrid ID="RadGrid_gsat" runat="server" AllowPaging="True" 
            AllowSorting="True" CellSpacing="0" DataSourceID="SqlDataSource_gsnuocthai" 
            GridLines="None" AllowAutomaticDeletes="True" AutoGenerateColumns="False"
            AllowAutomaticInserts="True" AllowAutomaticUpdates="True" OnItemUpdated="RadGrid_gsat_ItemUpdated"
             
           OnItemInserted="RadGrid_gsat_ItemInserted" Skin="Telerik">
         <MasterTableView AutoGenerateColumns="False" DataKeyNames="Mags" 
           DataSourceID="SqlDataSource_gsnuocthai" CommandItemDisplay="Top">
            
          <DetailTables>
                <telerik:GridTableView DataKeyNames="Mags,idct" DataSourceID="SqlDataSource_ct"
                               Width="100%" runat="server" CommandItemDisplay="Top" Name="Details">
                             
                               <ParentTableRelation>   
                                <telerik:GridRelationFields DetailKeyField="Mags" MasterKeyField="Mags" />
                               </ParentTableRelation>
                             
                                 <Columns>
                                   <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn1">
                                       <HeaderStyle Width="20px" />
                                       <ItemStyle CssClass="MyImageButton" />
                                   </telerik:GridEditCommandColumn>
                                   <telerik:GridBoundColumn SortExpression="Mags" HeaderText="Mags" HeaderButtonType="TextButton"
                                       DataField="Mags" UniqueName="Mags" ReadOnly="true" Visible="false">
                                   </telerik:GridBoundColumn>
                                   <telerik:GridDropDownColumn DataField="mact" DataSourceID="ctgs_ct"
                                         HeaderText="Chỉ tiêu" ListTextField="Tenchitieu" ListValueField="mact"
                                         UniqueName="mact" ColumnEditorID="GridDropDownColumnEditor3">
                                    </telerik:GridDropDownColumn>
                                  
                                  <telerik:GridNumericColumn SortExpression="nongdo" HeaderText="Nồng độ" DataField="nongdo" UniqueName="nongdo">                                  
                                  </telerik:GridNumericColumn>
                                   <telerik:GridButtonColumn ConfirmText="Delete muc giamsat nay?" ButtonType="ImageButton"
                                       CommandName="Delete" Text="Delete" UniqueName="DeleteColumn1">
                                       <HeaderStyle Width="20px" />
                                       <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                                   </telerik:GridButtonColumn>
                                   </Columns>
                                   <SortExpressions>
                                   <telerik:GridSortExpression FieldName="nongdo" SortOrder="Descending"></telerik:GridSortExpression>
                               </SortExpressions>
                        </telerik:GridTableView>
                    </DetailTables>
                          <Columns>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn2">
                                <HeaderStyle Width="20px" />
                                <ItemStyle CssClass="MyImageButton" />
                            </telerik:GridEditCommandColumn>
                            <telerik:GridBoundColumn SortExpression="Mags" HeaderText="Mags" HeaderButtonType="TextButton"
                                DataField="Mags" UniqueName="Mags" ReadOnly="true" Visible="false">
                            </telerik:GridBoundColumn>
                             
                             <telerik:GridTemplateColumn HeaderText="STT">
                               <ItemTemplate>
                                <asp:Label runat="server" ID="lblSTT" Text='<%#i++%>'></asp:Label>
                               </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            
                            <telerik:GridDropDownColumn DataField="Madnghiep" DataSourceID="giamsat_dn"
                        HeaderText="Doanhnghiep" ListTextField="TenDN" ListValueField="Madnghiep"
                        UniqueName="Madnghiep" ColumnEditorID="GridDropDownColumnEditor1">
                            </telerik:GridDropDownColumn>
                            
                             <telerik:GridDropDownColumn DataField="Madotgs" DataSourceID="giamsat_dotgs"
                        HeaderText="Đọt giám sát" ListTextField="Dotgiamsat" ListValueField="Madotgs"
                        UniqueName="Madotgs" ColumnEditorID="GridDropDownColumnEditor2">
                            </telerik:GridDropDownColumn>
                               
                                <telerik:GridNumericColumn DataField="Vitrido" 
                                    FilterControlAltText="Filter Vitrido column" HeaderText="Vitrido" 
                                    SortExpression="Vitrido" UniqueName="Vitrido">
                                </telerik:GridNumericColumn>
                                <telerik:GridNumericColumn DataField="Luuluong" 
                                    FilterControlAltText="Filter Luuluong column" HeaderText="Luuluong" 
                                    SortExpression="Luuluong" UniqueName="Luuluong">
                                </telerik:GridNumericColumn>
                                <telerik:GridBoundColumn DataField="Donvi" 
                                    FilterControlAltText="Filter Donvi column" HeaderText="Donvi" 
                                    SortExpression="Donvi" UniqueName="Donvi">
                                </telerik:GridBoundColumn>
                                
                                <telerik:GridBoundColumn DataField="Ghichu" ItemStyle-Width="100" ItemStyle-Height="50"
                                    FilterControlAltText="Filter Ghichu column" HeaderText="Ghichu" 
                                    SortExpression="Ghichu" UniqueName="Ghichu">
                                </telerik:GridBoundColumn>
                                
                                <telerik:GridDateTimeColumn DataField="Ngaynhap" DataType="System.DateTime" 
                                    FilterControlAltText="Filter Ngaynhap column" HeaderText="Ngaynhap" 
                                    SortExpression="Ngaynhap" UniqueName="Ngaynhap">
                                </telerik:GridDateTimeColumn>
                                 <telerik:GridButtonColumn ConfirmText="Delete muc nay?" ButtonType="ImageButton"
                                       CommandName="Delete" Text="Delete" UniqueName="DeleteColumn2">
                                       <HeaderStyle Width="20px" />
                                       <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                                   </telerik:GridButtonColumn>
                        </Columns>
                        <SortExpressions>
                            <telerik:GridSortExpression FieldName="Madnghiep"></telerik:GridSortExpression>
                        </SortExpressions>
                 
       </MasterTableView>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource_gsnuocthai" runat="server" 
        ConnectionString="<%$ ConnectionStrings:QLMTConnectionString %>" 
        SelectCommand="SELECT * FROM [Giamsatnuocthai]"
        DeleteCommand="Delete from Giamsatnuocthai where [Mags]=@original_Mags"
        InsertCommand="Insert into Giamsatnuocthai(Madnghiep,Madotgs,Vitrido,Luuluong,Donvi,Ghichu,Ngaynhap)VALUES (@Madnghiep,@Madotgs,@Vitrido,@Luuluong,@Donvi,@Ghichu,@Ngaynhap)"
        UpdateCommand="UPDATE [Giamsatnuocthai] SET [Madnghiep] = @Madnghiep, [Madotgs]=@Madotgs,[Vitrido]=@Vitrido,[Luuluong]=@Luuluong,[Donvi]=@Donvi,[Ghichu]=@Ghichu,[Ngaynhap]=@Ngaynhap WHERE [Mags] = @original_Mags"
        OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues">
        
        
        
            <DeleteParameters>
               <asp:Parameter Name="original_Mags" Type="Int32" />
           </DeleteParameters>
           <UpdateParameters>
               
                <asp:Parameter Name="Madnghiep" Type="Int32" />
                <asp:Parameter Name="Madotgs" Type="Int32" />
                <asp:Parameter Name="Vitrido" Type="String" />
                <asp:Parameter Name="Luuluong" Type="Double" />
                <asp:Parameter Name="Donvi" Type="String" />              
                <asp:Parameter Name="Ghichu" Type="String" />
                <asp:Parameter Name="Ngaynhap" Type="DateTime" />
               
                <asp:Parameter Name="original_Mags" Type="Int32" />
               
               
           </UpdateParameters>
           <InsertParameters>                
                <asp:Parameter Name="Madnghiep" Type="Int32" />
                <asp:Parameter Name="Madotgs" Type="Int32" />
                <asp:Parameter Name="Vitrido" Type="String" />
                <asp:Parameter Name="Luuluong" Type="String" />
                <asp:Parameter Name="Donvi" Type="String" />              
                <asp:Parameter Name="Ghichu" Type="String" />
                <asp:Parameter Name="Ngaynhap" Type="DateTime" />
           </InsertParameters>
        </asp:SqlDataSource>
         <asp:SqlDataSource ID="SqlDataSource_ct" runat="server" ProviderName="System.Data.SqlClient"
       ConnectionString="<%$ ConnectionStrings:QLMTConnectionString %>"
       SelectCommand="SELECT * FROM [Chitietgs]where Mags=@Mags"
       DeleteCommand="Delete from Chitietgs where [idct]=@original_idct"
       InsertCommand="Insert into Chitietgs(Mags,mact,nongdo)VALUES (@Mags,@mact,@nongdo)"
       UpdateCommand="UPDATE [Chitietgs] SET [mact]=@mact,[nongdo]=@nongdo WHERE [Mags] = @original_Mags"
       OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues">
       
       <SelectParameters>
               <asp:Parameter Name="Mags" Type="Int32" />
       </SelectParameters>
        <DeleteParameters>
               <asp:Parameter Name="original_idct" Type="Int32" />
              
        </DeleteParameters>
        <UpdateParameters>
               <asp:Parameter Name="Mags" Type="Int32" />
               <asp:Parameter Name="mact" Type="Int32" />
               <asp:Parameter Name="nongdo" Type="Double" />
               <asp:Parameter Name="original_Mags" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
               <asp:Parameter Name="Mags" Type="Int32" />
               <asp:Parameter Name="mact" Type="Int32" />
               <asp:Parameter Name="nongdo" Type="Double" />
        </InsertParameters>                      
      </asp:SqlDataSource>  
          <asp:SqlDataSource ID="giamsat_dn" runat="server" 
                ConnectionString="<%$ ConnectionStrings:QLMTConnectionString %>" 
                SelectCommand="SELECT [Madnghiep], [TenDN] FROM [Doanhnghiep]">
            </asp:SqlDataSource>
         <asp:SqlDataSource ID="giamsat_dotgs" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:QLMTConnectionString %>" 
                        SelectCommand="SELECT [Madotgs], [Dotgiamsat] FROM [Dotgiamsat]">
         </asp:SqlDataSource>
         <asp:SqlDataSource ID="ctgs_ct" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:QLMTConnectionString %>" 
                        SelectCommand="SELECT [mact], [Tenchitieu] FROM [Chitieunuoc]">
         </asp:SqlDataSource>
                     
</asp:Content>

